package com.wws.family.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.wika.basics.base.BaseActivity
import com.wws.family.R
import com.wws.family.databinding.ActivityMedicineDetailBinding
import com.wws.family.db.MedicineBean

/**
 *@Description:详情页
 *@Date: 2025/1/7 11:41
 *@Author: WangWeiShuo
 */
class MedicineDetailActivity: BaseActivity<ActivityMedicineDetailBinding>() {
    private lateinit var launcher: ActivityResultLauncher<Intent>

    override fun initView(savedInstanceState: Bundle?) {
        val medicineItem =  intent.getSerializableExtra("medicineItem") as MedicineBean
        setActionBar(R.drawable.baseline_arrow_back_white,medicineItem.name,R.color.white,R.color.blue_B8DCFF,-1,true,true)
        launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
            val intent = it.data
            if(intent != null){
                val medicineBean =  intent.getSerializableExtra("medicineBean") as MedicineBean
                if(medicineBean != null){
                    showMedicineInfo(medicineBean)
                }
            }
        }

        mBinding.btnEditMedicine.setOnClickListener {
            val intent = Intent(this@MedicineDetailActivity,MedicineAddActivity::class.java)
            intent.putExtra("medicineItem",medicineItem)
            launcher.launch(intent)
        }
        showMedicineInfo(medicineItem)
    }

    override fun initData() {

//        initMedicine()
    }

    override fun needFullScreen(): Boolean {
        return false
    }

    override fun actionBarRightClick() {

    }

    private fun showMedicineInfo(medicineItem: MedicineBean){
        mBinding.tvDetailFun.text = medicineItem.function
        mBinding.tvDetailMethod.text = medicineItem.method
        mBinding.tvDetailTotal.text = medicineItem.total
        mBinding.tvDetailRemain.text = medicineItem.remain
        mBinding.tvDetailEndTime.text = medicineItem.endTime
        when(medicineItem?.type){
            0 -> {
                mBinding.ivShared.background = getDrawable(R.drawable.icon_yaowan)
            }
            1 -> {
                mBinding.ivShared.background = getDrawable(R.drawable.icon_koufuye)
            }
            2 -> {
                mBinding.ivShared.background = getDrawable(R.drawable.icon_chongji)
            }
            else -> {
                mBinding.ivShared.background = getDrawable(R.drawable.icon_medicine_1)
            }
        }
    }
}